package com.asset.utils;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class UrlPath {

	public void saveToFile(String destUrl) {
		FileOutputStream fos = null;
		BufferedInputStream bis = null;
		HttpURLConnection httpUrl = null;
		URL url = null;
		int BUFFER_SIZE = 1024;
		byte[] buf = new byte[BUFFER_SIZE];
		int size = 0;
		try {
			url = new URL(destUrl);
			httpUrl = (HttpURLConnection) url.openConnection();
			httpUrl.connect();
			bis = new BufferedInputStream(httpUrl.getInputStream());
			fos = new FileOutputStream("C:/Users/Administrator/Desktop/haha.jpg");
			while ((size = bis.read(buf)) != -1) {
				fos.write(buf, 0, size);
			}
			fos.flush();
		} catch (IOException e) {
		} catch (ClassCastException e) {
		} finally {
			try {
				fos.close();
				bis.close();
				httpUrl.disconnect();
			} catch (IOException e) {
			} catch (NullPointerException e) {
			}
		}
	}

	public static void main(String[] args) {

		UrlPath dw = new UrlPath();
		
		dw.saveToFile("http://pic6.huitu.com/res/20130116/84481_20130116142820494200_1.jpg");
	    dw.saveToFile("http://localhost:8080/asset/getQRcode.action?text=http://10.51.4.119:8080/getAssetMessage.action?id=1&&identifer=002");
		String uri ="/asset/toLogin.action";
		String uri2 = uri.substring(uri.indexOf(".")+1, uri.indexOf(".")+7);
		System.out.println(uri2);
	}
}
